import axios from 'axios';
import Cookies from 'js-cookie';

const instance = axios.create({
    baseURL: '/api', // 假设 API 基础路径为 /api
    timeout: 5000
});

// 请求拦截器,在发送到后端之前，修改请求配置
instance.interceptors.request.use(
    (config) => {
        const token = Cookies.get('token');
        if (token) {
            config.headers.Authorization = `Bearer ${token}`;
        }
        return config;
    },
    (error) => Promise.reject(error)
);

export default instance;